<?php

/**
 *  @FileComment            [前台登陆控制器]
 *  @ProjectName             项目名称：ShopFrame
 *  @FileName                   文件名称：LoginController.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-4 21:42:25
 *  *
 */
class LoginController extends Controller {

        public function index() {
                $this->display();
        }

        public function ajax_login_check() {
                //ajax异步验证
                if (!IS_AJAX)
                        die('非法传参');
                $user = Q('post.username', '', 'trim');
                $passwd = Q('post.password', '', 'md5');
                $auto = Q('post.auto', 'off');
                $tempArr = array();
                $data = K('User')->where(array('username' => $user))->find();
                //验证用户是否存在
                if (!empty($data)) {
                        if (session('username') == $user) {
                                $tempArr['is_login'] = 1;
                        } else {
                                $tempArr['is_login'] = 0;
                        }
                        $tempArr['is_user'] = 1;
                        if ($data['password'] == $passwd) {
                                $tempArr['is_password'] = 1;
                                $_SESSION['username'] = $user;
                                $_SESSION['uid'] = $data['uid'];
                                if ($auto == 'on') {
                                        setcookie(session_name(), session_id(), time() + 3600 * 24 * 7, '/');
                                }
                        } else {
                                $tempArr['is_password'] = 0;
                        }
                } else {
                        $tempArr['is_user'] = 0;
                }
                $tempArr['url'] = U('Index/index');
                $this->ajax($tempArr);
        }

        public function out() {
                //退出登陆，清除自动登陆信息
                session(NULL);
                cookie(session_name(), NULL);
                go(U('Login/index'));
        }

}
